﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;

namespace ConsoleApp
{
    public class demo_dns
    {
        public static void demo()
        {
            string localhostname = Dns.GetHostName();
            Console.WriteLine("\tHost  Name: " + localhostname);

            PrintHostInfo(localhostname);

            PrintHostInfo("www.mkp.com");
            //PrintHostInfo("141.101.117.96");
        }

        private static void PrintHostInfo(String host)
        {
            try
            {
                //  Attempt  to  resolve  DNS  for  given  host  or  address
                IPHostEntry hostInfo = Dns.GetHostEntry(host);

                //  Display  the  primary  host  name
                Console.WriteLine("\tCanonical  Name:  " + hostInfo.HostName);

                //  Display  list  of  IP  addresses  for  this  host
                Console.WriteLine("\tIP  Addresses:      ");
                foreach (IPAddress ipaddr in hostInfo.AddressList)
                {
                    Console.WriteLine(ipaddr.ToString() + "  ");
                }
                Console.WriteLine();

                //  Display  list  of  alias  names  for  this  host
                Console.WriteLine("\tAliases: ");
                foreach (String alias in hostInfo.Aliases)
                {
                    Console.WriteLine(alias + "  ");
                }
                Console.WriteLine("\n");
            }
            catch (Exception)
            {
                Console.WriteLine("\tUnable  to  resolve  host:  " + host + "\n");
            }
        }
    }
}
